<?
	$test = "You must select at least {minDrivers} drivers.";
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<SCRIPT LANGUAGE="JavaScript">
// JavaScript Document
function updateRadio (val) 
{
	if(teamMembers.driverSelect[val].checked == true && 
	   teamMembers.captainSelect[val].disabled == true ) 
	{
		teamMembers.captainSelect[val].disabled=false;
	}
	else if(teamMembers.driverSelect[val].checked == false)
	{
		teamMembers.captainSelect[val].disabled=true;
		teamMembers.captainSelect[val].checked=false;
	}
}

function validateParams (minDrivers, maxDrivers) 
{
	captain = -1;
	for (i = 0; i < teamMembers.captainSelect.length && captain == -1; i++)
	{
		if(teamMembers.captainSelect[i].checked && !teamMembers.captainSelect[i].disabled)
			captain = i;
	}
	if(captain == -1)
	{
		window.alert("You must select a captain.");
		return false;
	}
	
	count = 0;
	for (i = 0; i < teamMembers.driverSelect.length; i++)
	{
		if(teamMembers.driverSelect[i].checked)
			count++;
	}
	if(count < minDrivers)
	{
		var message = "<?= $test ?>";
		window.alert( message.replace(/{minDrivers}/g, minDrivers));
		return false;
	}
	if(count > maxDrivers)
	{
		window.alert("You must select at most " + maxDrivers + " drivers.");
		return false;
	}
}
</SCRIPT>
<body>
<form name="teamMembers" action="multimembers.php" method="get" onsubmit="return validateParams(2,3)">
<table width="400" border="0">
  <tr>
    <td>&nbsp;</td>
    <td>Driver</td>
    <td>Captain</td>
  </tr>
  <tr>
    <td><input name="driverSelect" type="checkbox"  onClick="updateRadio(0)" value="0" checked/></td>
    <td>Alex Sawczuk</td>
    <td><input name="captainSelect" type="radio" value="0" /></td>
  </tr>
  <tr>
    <td><input name="driverSelect" type="checkbox" onClick="updateRadio(1)" value="1" checked /></td>
    <td>Jennie Anderzen</td>
    <td><input name="captainSelect" type="radio" value="1" /></td>
  </tr>
  <tr>
    <td><input name="driverSelect" type="checkbox" onClick="updateRadio(2)" value="2" checked /></td>
    <td>Luc Van Camp</td>
    <td><input name="captainSelect" type="radio" value="2" /></td>
  </tr>
  <tr>
    <td><input name="driverSelect" type="checkbox" onClick="updateRadio(3)" value="3" checked /></td>
    <td>Laurent Evenisse</td>
    <td><input name="captainSelect" type="radio" value="3" /></td>
  </tr>
  <tr>
    <td><input name="driverSelect" type="checkbox" onClick="updateRadio(4)" value="4" checked /></td>
    <td>Laurent Keersmaekers</td>
    <td><input name="captainSelect" type="radio" value="4" /></td>
  </tr>
</table>
<input name="Submit" type="submit" value="Submit"/>
</form>
</body>
</html>
